<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <title>自动化专业学习笔记</title>
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  <meta name="description" content="Description">
  <meta name="viewport"
    content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <link rel="icon" href="https://portrait.gitee.com/uploads/avatars/user/2532/7597569_chenliucx_1599386104.png"
    type="image/x-icon" />
  <link rel="stylesheet" href="https://cdn.staticfile.org/docsify/4.13.0/themes/vue.css" />
  <link rel="stylesheet" href="https://cdn.staticfile.org/docsify/4.13.0/themes/buble.css" disabled />
  <link rel="stylesheet" href="https://cdn.staticfile.org/docsify/4.13.0/themes/dark.css" disabled />
  <link rel="stylesheet" href="https://cdn.staticfile.org/docsify/4.13.0/themes/pure.css" disabled />
  <style>
  .katex-display{
    overflow-x: auto;
    overflow-y: hidden;
  }
  </style>
</head>

<body>

  <nav>
    <select id="control">
      <optgroup label="主题">
        <option value="vue">vue</option>
        <option value="buble">buble</option>
        <option value="dark">暗色</option>
        <option value="pure">纯净</option>
      </optgroup>
      <optgroup label="刷新">
        <option value="filelist">从gitee获取文件列表</option>
      </optgroup>
    </select>
    <a href="#/content.md">目录</a>
  </nav>
  <script>
    //函数：更换docsify主题
    function changeTheme(title) {
      const themes = document.querySelectorAll('head [rel="stylesheet"]');
      localStorage.setItem("docsify.theme", title)
      let all_disabled = true;
      themes.forEach(function (theme) {
        theme.disabled = !theme.href.includes(title);
        all_disabled &= theme.disabled;
      });
      if (all_disabled) {
        console.warn(`the css title ${title} is not a valid one`, themes);
        console.warn(`use first css ${themes[0].href}`);
        themes[0].disabled = false;
      }
    }
    //函数：从gitee API获取当前仓库的文件树，需要仓库开源，主要用于支持搜索功能
    function updateFiles() {
      return fetch("https://gitee.com/api/v5/repos/xsro/college-notes/git/trees/main?recursive=1")
        .then(val => val.text())
        .then(val => {
          const files = JSON.parse(val);
          const markdownFiles = files.tree.map(val => val.path).filter(val => val.endsWith(".md"))
          localStorage.setItem("docsify.mds.list", markdownFiles.join(','));
          localStorage.setItem("docsify.mds.updateTime", Date.now());
          console.log("updated")
          return markdownFiles;
        })
    }

    //超时自动更新文件树
    const lastUpdateListTime = localStorage.getItem("docsify.mds.updateTime");
    if (!lastUpdateListTime || Date.now() - lastUpdateListTime > 1000 * 60 * 24) {
      updateFiles();
    }

    //手动更换主题或刷新文件树
    const control = document.getElementById("control")
    control.value = localStorage.getItem("docsify.theme") ?? "vue"
    changeTheme(control.value);
    control.addEventListener(
      "input", e => {
        if (e.target.value === "filelist") {
          localStorage.clear()
          updateFiles().then(
            files => {
              alert("reload " + files.length + " files");
              location.reload()
            }
          ).catch(e => {
            alert("fetch failed" + e)
          })
        } else {
          changeTheme(e.target.value);
        }
      }
    )
  </script>


  <div id="app"></div>
  <script>
    window.$docsify = {
      name: '<span>大学笔记</span>',
      repo: 'https://gitee.com/xsro/college-notes',
      coverpage: true,
      onlyCover: false,
      plugins: [
        // https://docsify.js.org/#/write-a-plugin?id=write-a-plugin
        function (hook, vm) {
          hook.init(function () {
            // Called when the script starts running, only trigger once, no arguments,
          });

          hook.beforeEach(function (content) {
            // Invoked each time before parsing the Markdown file.

            // edit on gitee and markmap by https://docsify.js.org/#/write-a-plugin?id=edit-button
            const prefix = document.location.pathname.endsWith('/') ? '' : '..';
            const markmapUrl = new URL(prefix + 'markmap.html', document.location);
            const markdownUrl = new URL(prefix + vm.route.file, document.location);
            markmapUrl.searchParams.set("md", markdownUrl.pathname)
            content = `[📝 EDIT](https://gitee.com/xsro/college-notes/edit/main/${vm.route.file})\t`
              + `[📚 VIEW](https://gitee.com/xsro/college-notes/blob/main/${vm.route.file})\t`
              + `[🎇 MARKMAP](${markmapUrl})\n\n` + content;

            //write all files list, this list is used for search and can be different from the deployed files
            const _files = localStorage.getItem("docsify.mds.list");
            const _time = localStorage.getItem("docsify.mds.updateTime");
            if (_files && _time && content.includes("<!-- generate File list here -->")) {
              const files = _files.split(",");
              const dup = (val, times) => new Array(times).fill(val).join("")
              let str = "";
              let lastSegs = [];
              for (const file of files) {
                segs = file.split("/").filter(val => val.length > 0);
                for (let i = 0; i < segs.length; i++) {
                  if (i < lastSegs.length && segs[i] === lastSegs[i]) {
                  }
                  else if (i === segs.length - 1) {
                    str += `${dup("\t", i)}- [${segs[i]}](${file})\n`;
                  }
                  else {
                    str += `${dup("\t", i)}- ${segs[i]}\n`;
                  }
                }
                lastSegs = segs
              }
              const filesList = files.map(val => `- [${val}](${val})`).join("\n");
              const header = `\nupdate at \`${new Date(parseInt(_time)).toLocaleString()}\`\n\n`;
              content = content.replace("<!-- generate File list here -->", header + str)
            }

            return content;
          });

          hook.afterEach(function (html, next) {
            // Invoked each time after the Markdown file is parsed.
            // beforeEach and afterEach support asynchronous。
            // ...
            // call `next(html)` when task is done.
            next(html);
          });

          hook.doneEach(function () {
            // Invoked each time after the data is fully loaded, no arguments,
            // ...
          });

          hook.mounted(function () {
            // Called after initial completion. Only trigger once, no arguments.
            // use gitee corner following https://github.com/Koooooo-7/docsify-corner 
            const icon = "https://gitee.com/xsro/college-notes/widgets/widget_1.svg"
            const a = document.querySelector('a.github-corner')
            a.href = 'https://gitee.com/xsro/college-notes'
            a.innerHTML = `<img docsify-corner src=${icon} width= 80 height = 80>`
          });

          hook.ready(function () {
            // Called after initial completion, no arguments.
          });
        }],
      search: {
        maxAge: 1000,
        paths: ["README.md", "content.md"]
      }
    };
  </script>
  <script src="https://cdn.staticfile.org/docsify/4.13.0/docsify.min.js"></script>


  <!-- full text search https://docsify.js.org/#/plugins?id=full-text-search -->
  <script>
    const files = localStorage.getItem("docsify.mds.list");
    if (files) {
      const _files = files.split(",");
      window.$docsify.search = {
        placeholder: {
          '/': '搜索'
        },
        paths: _files
      };
    }
  </script>
  <script src="https://cdn.staticfile.org/docsify/4.13.0/plugins/search.min.js"></script>

  <!-- support mermaid following https://docsify.js.org/#/markdown?id=supports-mermaid -->
  <script src="https://cdn.staticfile.org/mermaid/8.13.10/mermaid.min.js"></script>
  <script>
    var num = 0;
    mermaid.initialize({ startOnLoad: false });
    window.$docsify.markdown =
    {
      renderer: {
        code: function (code, lang) {
          if (lang === "mermaid") {
            return (
              '<div class="mermaid">' + mermaid.render('mermaid-svg-' + num++, code) + "</div>"
            );
          }
          return this.origin.code.apply(this, arguments);
        }
      }
    };
  </script>


  <!-- support katex following https://github.com/upupming/docsify-katex#usage-->
  <script defer src="https://cdn.bootcdn.net/ajax/libs/KaTeX/0.15.2/katex.min.js"></script>
  <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/KaTeX/0.15.2/katex.min.css">
  <script>
    window.$docsify.plugins.push(
      function (hook, vm) {
        let blocks = [];
        hook.beforeEach(function (mdstr) {
          for (const r of mdstr.matchAll(/[^\\]\$\$([\s\S]*?[^\\])\$\$/g)) {
            mdstr = mdstr.replace(r[0], `[math[${blocks.length}]]`)
            blocks.push([r[0], r[1], true])
          }
          for (const r of mdstr.matchAll(/\$(.*?[^\\])\$/g)) {
            mdstr = mdstr.replace(r[0], `[math[${blocks.length}]]`)
            blocks.push([r[0], r[1], false])
          }
          return mdstr
        });
        hook.afterEach(function (html, next) {
          for (const index in blocks) {
            const [full, tex, display] = blocks[index];
            let rendered = ""
            if (typeof katex !== "undefined") {
              try{
                rendered = katex.renderToString(tex, {
                  throwOnError: true,
                  displayMode: display,
                })
              }catch(e){
                rendered = `<span style="color: red;">${e}</span>`
              }
            } else {
              rendered = `<a title="${full}">[${display ? "block" : "inline"}math[${blocks.length - index}]]</a>`;
            }
            html = html.replace(`[math[${index}]]`, rendered)
          }
          next(html)
        })
      }
    );
  </script>


  <!-- code syntax  https://docsify.js.org/#/language-highlight-->
  <script src="https://cdn.bootcdn.net/ajax/libs/prism/1.26.0/components/prism-nasm.min.js"></script>
  <script src="https://cdn.bootcdn.net/ajax/libs/prism/1.26.0/components/prism-python.min.js"></script>
  <script src="https://cdn.bootcdn.net/ajax/libs/prism/1.26.0/components/prism-matlab.min.js"></script>
  <script>
    //use nasm as syntax for assembly
    Prism.languages.assembly = Prism.languages.nasm
  </script>

</body>

</html>